#ifndef OBJECT_H
#define OBJECT_H

#include "SFML\System.hpp"
#include "SFML\Graphics.hpp"

class Object
{
protected:
	virtual ~Object();  // Note: Virtual destructor because we have virtual methods
	friend class Factory;

public:
	Object(const sf::Texture &texture);

	// Abstract virtual functions: (This makes our class abstract)
	virtual void Render(sf::RenderWindow &win) { win.draw(sprite); };
	virtual void Update(float deltaTime) = 0;
	virtual bool Alert(sf::Event &e) { return false; }

	// Variables that all objects have:
	sf::Sprite sprite;
};


class Car;

class Body : public Object
{
public:
	Body(const sf::Texture &texture) : Object(texture) 
	{
		velocity = 0.0f;
		dead = false;
	}

	void Update( float deltaTime );
	void Render(sf::RenderWindow &win);
	void DIE( Car *car );

	float velocity;
	float dead;
};


class Car : public Object
{
public:
	Car(const sf::Texture &texture, sf::Texture &deadTex, Body *b) : Object(texture), body(b), deadTexture(deadTex)
	{
		W = A = S = D = Space = false;
		seatbelt = false;
		dead = false;

		isDriven = false;

		velocity = 0.0f;

		font.loadFromFile("arial.ttf");

		deadText.setFont(font);
		deadText.setPosition(20, 20);

		seatbeltText.setFont(font);
		seatbeltText.setPosition(20, 768 - 80);
	}

	void Update(float deltaTime);
	void Render( sf::RenderWindow &win );
	virtual bool Alert(sf::Event &e);

	bool W, A, S, D, Space;
	bool seatbelt;
	bool dead;
	float velocity;

	bool isDriven;

	Body *body;

	sf::Texture &deadTexture;

	sf::Font font;
	sf::Text seatbeltText;
	sf::Text deadText;
};

class Car;
class PlayerChar : public Object
{
public:
	PlayerChar(const sf::Texture &texture, sf::Texture &deadTex, Car *c) : Object(texture), car(c), deadTexture(deadTex)
	{
		W = A = S = D = false;
		dead = false;
	}

	void Update(float deltaTime);
	void Render(sf::RenderWindow &win);
	virtual bool Alert(sf::Event &e);

	sf::Texture &deadTexture;

	bool W, A, S, D;
	Car *car;
	bool dead;
};

#endif // OBJECT_H